package javolution.util;

import java.io.ObjectStreamException;
import javax.realtime.MemoryArea;
import javolution.lang.Configurable;
import javolution.lang.Immutable;
import javolution.util.FastCollection;
import javolution.xml.XMLSerializable;

/* loaded from: classes2.dex */
public final class Index extends Number implements Comparable<Index>, FastCollection.Record, Immutable, XMLSerializable {
    private static final Runnable AUGMENT_NEGATIVE;
    private static final Runnable AUGMENT_POSITIVE;
    private static final MemoryArea IMMORTAL_MEMORY;
    private static final int INCREASE_AMOUNT = 16;
    private static Index[] NegativeIndices = null;
    private static int NegativeIndicesLength = 0;
    static volatile boolean NoReordering = false;
    private static int PositiveIndicesLength = 0;
    private static final long serialVersionUID = 1;
    private final int _value;
    public static final Configurable<Integer> INITIAL_FIRST = new Configurable(new Integer(-1)) { // from class: javolution.util.Index.1
        @Override // javolution.lang.Configurable
        protected void notifyChange() {
            Index.valueOf(Index.INITIAL_FIRST.get().intValue());
        }
    };
    public static final Configurable<Integer> INITIAL_LAST = new Configurable(new Integer(16)) { // from class: javolution.util.Index.2
        @Override // javolution.lang.Configurable
        protected void notifyChange() {
            Index.valueOf(Index.INITIAL_LAST.get().intValue());
        }
    };
    public static final Index ZERO = new Index(0);
    private static Index[] PositiveIndices = new Index[16];

    static {
        Index[] indexArr = PositiveIndices;
        Index index = ZERO;
        indexArr[0] = index;
        PositiveIndicesLength = 1;
        NegativeIndices = new Index[16];
        NegativeIndices[0] = index;
        IMMORTAL_MEMORY = MemoryArea.getMemoryArea(new Object());
        NegativeIndicesLength = 1;
        AUGMENT_POSITIVE = new Runnable() { // from class: javolution.util.Index.3
            @Override // java.lang.Runnable
            public void run() {
                int i = Index.PositiveIndicesLength + 16;
                for (int i2 = Index.PositiveIndicesLength; i2 < i; i2++) {
                    Index index2 = new Index(i2);
                    if (Index.PositiveIndices.length <= i2) {
                        Index[] indexArr2 = new Index[Index.PositiveIndices.length * 2];
                        System.arraycopy(Index.PositiveIndices, 0, indexArr2, 0, Index.PositiveIndices.length);
                        Index[] unused = Index.PositiveIndices = indexArr2;
                    }
                    Index.PositiveIndices[i2] = index2;
                }
                Index.NoReordering = true;
                Index.access$012(16);
            }
        };
        AUGMENT_NEGATIVE = new Runnable() { // from class: javolution.util.Index.4
            @Override // java.lang.Runnable
            public void run() {
                int i = Index.NegativeIndicesLength + 16;
                for (int i2 = Index.NegativeIndicesLength; i2 < i; i2++) {
                    Index index2 = new Index(-i2);
                    if (Index.NegativeIndices.length <= i2) {
                        Index[] indexArr2 = new Index[Index.NegativeIndices.length * 2];
                        System.arraycopy(Index.NegativeIndices, 0, indexArr2, 0, Index.NegativeIndices.length);
                        Index[] unused = Index.NegativeIndices = indexArr2;
                    }
                    Index.NegativeIndices[i2] = index2;
                }
                Index.NoReordering = true;
                Index.access$312(16);
            }
        };
        valueOf(INITIAL_FIRST.get().intValue());
        valueOf(INITIAL_LAST.get().intValue());
    }

    private Index(int i) {
        this._value = i;
    }

    static /* synthetic */ int access$012(int i) {
        int i2 = PositiveIndicesLength + i;
        PositiveIndicesLength = i2;
        return i2;
    }

    static /* synthetic */ int access$312(int i) {
        int i2 = NegativeIndicesLength + i;
        NegativeIndicesLength = i2;
        return i2;
    }

    private static synchronized Index createNegative(int i) {
        synchronized (Index.class) {
            if (i < NegativeIndicesLength) {
                return NegativeIndices[i];
            }
            while (i >= NegativeIndicesLength) {
                IMMORTAL_MEMORY.executeInArea(AUGMENT_NEGATIVE);
            }
            return NegativeIndices[i];
        }
    }

    private static synchronized Index createPositive(int i) {
        synchronized (Index.class) {
            if (i < PositiveIndicesLength) {
                return PositiveIndices[i];
            }
            while (i >= PositiveIndicesLength) {
                IMMORTAL_MEMORY.executeInArea(AUGMENT_POSITIVE);
            }
            return PositiveIndices[i];
        }
    }

    public static void setMinimumRange(int i, int i2) {
        if (i > i2) {
            throw new IllegalArgumentException();
        }
        valueOf(i);
        valueOf(i2);
    }

    public static Index valueOf(int i) {
        return i >= 0 ? i < PositiveIndicesLength ? PositiveIndices[i] : createPositive(i) : valueOfNegative(-i);
    }

    private static Index valueOfNegative(int i) {
        return i < NegativeIndicesLength ? NegativeIndices[i] : createNegative(i);
    }

    @Override // java.lang.Comparable
    public int compareTo(Index index) {
        return this._value - index._value;
    }

    @Override // java.lang.Number
    public final double doubleValue() {
        return intValue();
    }

    public final boolean equals(Object obj) {
        return this == obj;
    }

    @Override // java.lang.Number
    public final float floatValue() {
        return intValue();
    }

    @Override // javolution.util.FastCollection.Record
    public final FastCollection.Record getNext() {
        return valueOf(this._value + 1);
    }

    @Override // javolution.util.FastCollection.Record
    public final FastCollection.Record getPrevious() {
        return valueOf(this._value - 1);
    }

    public final int hashCode() {
        return this._value;
    }

    @Override // java.lang.Number
    public final int intValue() {
        return this._value;
    }

    @Override // java.lang.Number
    public final long longValue() {
        return intValue();
    }

    protected final Object readResolve() throws ObjectStreamException {
        return valueOf(this._value);
    }

    public final String toString() {
        return String.valueOf(this._value);
    }
}
